package com.ruoyi.project.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysAddress;
import com.ruoyi.project.system.service.ISysAddressService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 位置Controller
 * 
 * @author orange
 * @date 2022-04-08
 */
@RestController
@RequestMapping("/system/address")
public class SysAddressController extends BaseController
{
    @Autowired
    private ISysAddressService sysAddressService;

    /**
     * 查询位置列表
     */
    @PreAuthorize("@ss.hasPermi('system:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAddress sysAddress)
    {
        startPage();
        List<SysAddress> list = sysAddressService.selectSysAddressList(sysAddress);
        return getDataTable(list);
    }

    /**
     * 导出位置列表
     */
    @PreAuthorize("@ss.hasPermi('system:address:export')")
    @Log(title = "位置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAddress sysAddress)
    {
        List<SysAddress> list = sysAddressService.selectSysAddressList(sysAddress);
        ExcelUtil<SysAddress> util = new ExcelUtil<SysAddress>(SysAddress.class);
        util.exportExcel(response, list, "位置数据");
    }

    /**
     * 获取位置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:address:query')")
    @GetMapping(value = "/{addressId}")
    public AjaxResult getInfo(@PathVariable("addressId") Long addressId)
    {
        return AjaxResult.success(sysAddressService.selectSysAddressByAddressId(addressId));
    }

    /**
     * 新增位置
     */
    @PreAuthorize("@ss.hasPermi('system:address:add')")
    @Log(title = "位置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAddress sysAddress)
    {
        return toAjax(sysAddressService.insertSysAddress(sysAddress));
    }

    /**
     * 修改位置
     */
    @PreAuthorize("@ss.hasPermi('system:address:edit')")
    @Log(title = "位置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAddress sysAddress)
    {
        return toAjax(sysAddressService.updateSysAddress(sysAddress));
    }

    /**
     * 删除位置
     */
    @PreAuthorize("@ss.hasPermi('system:address:remove')")
    @Log(title = "位置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{addressIds}")
    public AjaxResult remove(@PathVariable Long[] addressIds)
    {
        return toAjax(sysAddressService.deleteSysAddressByAddressIds(addressIds));
    }
}
